/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.to.aboomy.bannersample.indicator.magicindicator;

import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * ColorFlipPagerTitleView
 *
 * @since 2020-09-29
 */
public class ColorFlipPagerTitleView extends SimplePagerTitleView {
    private static final float NUMO5 = 0.5f;
    private float changepercent = NUMO5;

    /**
     * ColorFlipPagerTitleView
     *
     * @param context context
     */
    public ColorFlipPagerTitleView(Context context) {
        super(context);
    }

    @Override
    public void onLeave(int index, int totalCount, float leavePercent, boolean isLeftToRight) {
        if (leavePercent >= changepercent) {
            setTextColor(new Color(mNormalColor));
        } else {
            setTextColor(new Color(mSelectedColor));
        }
    }

    @Override
    public void onEnter(int index, int totalCount, float enterPercent, boolean isLeftToRight) {
        if (enterPercent >= changepercent) {
            setTextColor(new Color(mSelectedColor));
        } else {
            setTextColor(new Color(mNormalColor));
        }
    }

    @Override
    public void onSelected(int index, int totalCount) {
    }

    @Override
    public void onDeselected(int index, int totalCount) {
    }

    public float getChangePercent() {
        return changepercent;
    }

    public void setChangePercent(float changePercent) {
        changepercent = changePercent;
    }
}
